#include <iostream>
#include <string>

using namespace std;

class stu
{
private:
    int val;

public:
    int *ptr;

public:
    stu() : val(10)
    {
    }
    stu(int val, int ptr_val) : val(val), ptr(new int(ptr_val))
    {
    }
    stu(const stu &other)
    {
        cout << "调用拷贝构造函数" << endl;
        if (NULL == other.ptr)
        {
            ptr = other.ptr;
        }
        else
        {
            ptr = new int(*other.ptr);
        }

        val = other.val;
    }

    ~stu()
    {
        if (NULL != ptr)
        {
            cout << "调用析构 释放空间完成" << endl;
            delete ptr;
        }
    }

public:
    void show()
    {
        cout << val << endl;
        cout << *ptr << endl;
    }

};

int main(int argc, char const *argv[])
{
    stu s1(10 , 20);

    stu s2(s1);

    *s1.ptr = 90;

    s2.show();



    return 0;
}
